#include "TIM4er.h"

#define TIM4Period      8
#define TIM4Prescaler   9

void TIM4_Init(void)
{
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStruct;
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4,ENABLE);    
    TIM_TimeBaseStruct.TIM_Period=TIM4Period;
    TIM_TimeBaseStruct.TIM_Prescaler=TIM4Prescaler;
    TIM_TimeBaseStruct.TIM_ClockDivision=0;
    TIM_TimeBaseStruct.TIM_CounterMode=TIM_CounterMode_Up;
    TIM_TimeBaseInit(TIM4,&TIM_TimeBaseStruct);
    TIM_ARRPreloadConfig(TIM4,ENABLE);
}



void TIMDelay_Nus(int Times)//u16 Times
{
    TIM4->CR1 |=TIM_CR1_CEN;
    while(Times--)
    {
        while((TIM4->SR & TIM_FLAG_Update)==RESET);
        TIM4->SR &= ~TIM_FLAG_Update;    
    }
    TIM4->CR1 &=~TIM_CR1_CEN;
}



void TIMDelay_Nms(int Times)
{
    while(Times--)
    {
       TIMDelay_Nus(1000); 
    }

}